package chabernac.android.wordbattle.model;

import java.util.List;

public class HorizontalVerticalSelectionHelper implements iSelectionHelper {

  @Override
  public boolean isSelectionAllowed(WordRaster aRaster, Letter aNewLetterToSelect) {
    List<Letter> theSelectedLetters = aRaster.getSelectedLetters();
    if(!theSelectedLetters.isEmpty()){
      Letter theLastSelectedLetter = theSelectedLetters.get(theSelectedLetters.size() - 1);
      int theHorizontalDiff = Math.abs(theLastSelectedLetter.getColumn() - aNewLetterToSelect.getColumn()); 
      int theVericalDiff = Math.abs(theLastSelectedLetter.getRow() - aNewLetterToSelect.getRow());
      if(theHorizontalDiff > 1) return false;
      if(theVericalDiff > 1) return false;
      
      if(theHorizontalDiff == 1 && theVericalDiff == 1) return false;
    }
    
    return true;
  }

  @Override
  public boolean isDiagonalSelectionGapNeeded() {
    return false;
  }

}
